/**
 * 
 */
package com.axxc.jpa.web;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.axxc.jpa.entity.StudentEntity;
import com.axxc.jpa.out.model.Student;
import com.axxc.jpa.service.IStudentService;
import com.axxc.jpa.vo.ResponseVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @ClassName: StudentController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author 熊小川
 * @date 2018年4月9日 下午10:19:46
 */
@RestController
@RequestMapping("student")
@Api(value = "用户controller", tags = { "student操作接口" })
public class StudentController extends AbstractStudentCrudController<Student, Long> {

	protected Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private IStudentService studentService;

	@GetMapping("nameStartingWith")
	@ApiOperation(value = "根据姓氏查询所有匹配学生")
	public List<StudentEntity> findByNameStartingWith(
			@ApiParam(value = "姓氏", required = true, example = "熊") @RequestParam(name = "name") String name) {
		List<StudentEntity> list = studentService.findByNameStartingWith(name);

		for (StudentEntity e : list) {
			logger.info("json:{}", e.toJsonString());
		}
		return list;

	}

	@GetMapping("listAllStudent")
	@ApiOperation(value = "查询所有学生")
	public ResponseVO<List<StudentEntity>> listAllStudent() {

		List<StudentEntity> allStudent = this.studentService.listAllStudent();
		ResponseVO<List<StudentEntity>> vo = new ResponseVO<List<StudentEntity>>(allStudent);
		vo.setTotal(allStudent.size() * 1L);
		return vo;
	}

	@GetMapping("updateStudent")
	@ApiOperation(value = "修改学生信息")
	public StudentEntity updateStudent(@ModelAttribute StudentEntity e) {
		return this.studentService.updateStudent(e.getId(), e);
	}
	
	@GetMapping("getStudentById/{id}")
	@ApiOperation(value = "通过Id查询学生信息")
	public StudentEntity getStudentById(@PathVariable Long id) {
		return this.studentService.getStudentById(id);
	}

}
